package com.hqyj.javaSpringCloudWeb.modules.account.service.impl;

import com.sfac.entity.account.User;
import com.sfac.entity.common.Result;
import com.hqyj.javaSpringCloudWeb.modules.account.service.AccountFeignClient;
import com.hqyj.javaSpringCloudWeb.modules.account.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description UserServiceImpl
 * @Author HymanHu
 * @Date 2021/9/6 9:09
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private AccountFeignClient feignClient;

    @Override
    public Result<User> login(HttpServletRequest request, User user) {
        Result<User> result = feignClient.login(user);
        if (result.getStatus() == Result.ResultCode.SUCCESS.code) {
            request.getSession().setAttribute("user", user);
        }
        return result;
    }

    @Override
    public Result<User> insertUser(HttpServletRequest request, User user) {
        Result<User> result = feignClient.insertUser(user);
        if (result.getStatus() == Result.ResultCode.SUCCESS.code) {
            request.getSession().setAttribute("user", user);
        }
        return result;
    }

    @Override
    public void logout(HttpServletRequest request) {
        request.getSession().setAttribute("user", null);
    }
}
